﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Reflection;

namespace WodLib
{
    [Serializable()]
    [System.ComponentModel.TypeConverter(typeof(System.ComponentModel.ExpandableObjectConverter))]
    public class HumanAttributes : ICloneable
    {
        public event EventHandler AnyHasChanged;
    

        [System.ComponentModel.Description("Mental, Power")]
        public Attribute Inteligence { get; set; }
        [System.ComponentModel.Description("Mental, Finesse")]
        public Attribute Witts { get; set; }
        [System.ComponentModel.Description("Mental, Resistance")]
        public Attribute Resolve { get; set; }
        [System.ComponentModel.Description("Physical, Power")]
        public Attribute Strength { get; set; }
        [System.ComponentModel.Description("Physical, Finesse")]
        public Attribute Dexterity { get; set; }
        [System.ComponentModel.Description("Physical, Resistance")]
        public Attribute Stamina { get; set; }
        [System.ComponentModel.Description("Social, Power")]
        public Attribute Presence { get; set; }
        [System.ComponentModel.Description("Social, Finesse")]
        public Attribute Manipulation { get; set; }
        [System.ComponentModel.Description("Social, Resistance")]
        public Attribute Composure { get; set; }

        /// <summary>
        /// Creates human attributes set.
        /// </summary>
        public HumanAttributes()
        {
            #region Mental attributes

            Inteligence = new Attribute(TraitType.Mental,AttributeCathegory.Power);
            Inteligence.HasChanged += new EventHandler(Attribute_HasChanged);

            Witts = new Attribute(TraitType.Mental, AttributeCathegory.Finesse);
            Witts.HasChanged += new EventHandler(Attribute_HasChanged);

            Resolve = new Attribute(TraitType.Mental, AttributeCathegory.Resistance);
            Resolve.HasChanged += new EventHandler(Attribute_HasChanged);
            #endregion
            #region Physical attributes
            Strength = new Attribute(TraitType.Physical, AttributeCathegory.Power);
            Strength.HasChanged += new EventHandler(Attribute_HasChanged);

            Dexterity = new Attribute(TraitType.Physical, AttributeCathegory.Finesse);
            Dexterity.HasChanged += new EventHandler(Attribute_HasChanged);

            Stamina = new Attribute(TraitType.Physical, AttributeCathegory.Resistance);
            Stamina.HasChanged += new EventHandler(Attribute_HasChanged);
            #endregion
            #region Social attributes
            Presence = new Attribute(TraitType.Social, AttributeCathegory.Power);
            Presence.HasChanged += new EventHandler(Attribute_HasChanged);

            Manipulation = new Attribute(TraitType.Social, AttributeCathegory.Finesse);
            Manipulation.HasChanged += new EventHandler(Attribute_HasChanged);

            Composure = new Attribute(TraitType.Social, AttributeCathegory.Resistance);
            Composure.HasChanged += new EventHandler(Attribute_HasChanged);
            #endregion

        }

        void Attribute_HasChanged(object sender, EventArgs e)
        {
            this.AnyHasChanged(sender, e);
        }

        #region ICloneable Members

        public object Clone()
        {
            HumanAttributes tmp = (HumanAttributes)this.MemberwiseClone();
            
            Type tp = this.GetType();
            System.Reflection.PropertyInfo[] props = tp.GetProperties();
            foreach (var item in props)
            {
                item.SetValue(tmp,
                    ((ICloneable)item.GetValue(this, null)).Clone(), null);
            }
            return tmp;
        }

        #endregion
    }
}
